home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Ports / alfa / measure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-18  |  743 b   |  62 lines  |  [TEXT/????]

  1. /* STANDARD WINDOWS -- TEXT MEASURING. */
  2.  
  3. #include "alfa.h"
  4.  
  5. int
  6. wlineheight()
  7. {
  8.     return 1;
  9. }
  10.  
  11. int
  12. wbaseline()
  13. {
  14.     return 1;
  15. }
  16.  
  17. #define CHARWIDTH(c) ((c) < ' ' ? 2 : (c) < 0177 ? 1 : (c) < 0200 ? 2 : 4)
  18.  
  19. int
  20. wtextwidth(str, len)
  21.     char *str;
  22.     int len;
  23. {
  24.     int i;
  25.     int w= 0;
  26.     
  27.     if (len < 0)
  28.         len= strlen(str);
  29.     for (i= 0; i < len; ++i) {
  30.         unsigned char c= str[i];
  31.         w += CHARWIDTH(c);
  32.     }
  33.     return w;
  34. }
  35.  
  36. int
  37. wcharwidth(c)
  38.     int c;
  39. {
  40.     c &= 0xff;
  41.     return CHARWIDTH(c);
  42. }
  43.  
  44. int
  45. wtextbreak(str, len, width)
  46.     char *str;
  47.     int len;
  48.     int width;
  49. {
  50.     int i;
  51.     
  52.     if (len < 0)
  53.         len= strlen(str);
  54.     for (i= 0; i < len && width > 0; ++i) {
  55.         unsigned char c= str[i];
  56.         width -= CHARWIDTH(c);
  57.         if (width < 0)
  58.             break; /* Before incrementing i! */
  59.     }
  60.     return i;
  61. }
  62.